package com.jack006.user.controller;

import com.jack006.api.BaseController;
import com.jack006.api.controller.user.MyFansControllerApi;
import com.jack006.grace.result.GraceJSONResult;
import com.jack006.grace.result.ResponseStatusEnum;
import com.jack006.pojo.vo.FansCountsVO;
import com.jack006.pojo.vo.RegionRatioVO;
import com.jack006.user.service.MyFansService;
import com.jack006.utils.PagedGridResult;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname HelloController
 * @Description 接口实现类
 * @Date 2021-06-10 08:15
 * @Created by jack
 */
@RestController
public class MyFansController extends BaseController implements MyFansControllerApi {

    final static Logger logger = LoggerFactory.getLogger(MyFansController.class);

    @Autowired
    private MyFansService myFansService;

    @Override
    public GraceJSONResult isMeFollowThisWriter(String writerId, String fanId) {
        if(StringUtils.isBlank(writerId)){
            return  GraceJSONResult.errorCustom(ResponseStatusEnum. WRITER_ID_IS_NULL_ERROR);
        }

        if(StringUtils.isBlank(fanId)){
            return  GraceJSONResult.errorCustom(ResponseStatusEnum. FAN_ID_IS_NULL_ERROR);
        }

        boolean meFollowThisWriter = myFansService.isMeFollowThisWriter(writerId, fanId);
        return GraceJSONResult.ok(meFollowThisWriter);
    }

    @Override
    public GraceJSONResult follow(String writerId, String fanId) {

        if(StringUtils.isBlank(writerId)){
            return  GraceJSONResult.errorCustom(ResponseStatusEnum. WRITER_ID_IS_NULL_ERROR);
        }

        if(StringUtils.isBlank(fanId)){
            return  GraceJSONResult.errorCustom(ResponseStatusEnum. FAN_ID_IS_NULL_ERROR);
        }

        myFansService.follow(writerId,fanId);

        return GraceJSONResult.ok();
    }

    @Override
    public GraceJSONResult unfollow(String writerId, String fanId) {
        if(StringUtils.isBlank(writerId)){
            return  GraceJSONResult.errorCustom(ResponseStatusEnum. WRITER_ID_IS_NULL_ERROR);
        }

        if(StringUtils.isBlank(fanId)){
            return  GraceJSONResult.errorCustom(ResponseStatusEnum. FAN_ID_IS_NULL_ERROR);
        }

        myFansService.unFollow(writerId,fanId);

        return GraceJSONResult.ok();
    }

    @Override
    public GraceJSONResult queryAll(String writerId, Integer page, Integer pageSize) {

        if (StringUtils.isBlank(writerId)) {
            return GraceJSONResult.errorCustom(ResponseStatusEnum.WRITER_ID_IS_NULL_ERROR);
        }

        if (page == null) {
            page = COMMON_START_PAGE;
        }

        if (pageSize == null) {
            pageSize = COMMON_PAGE_SIZE;
        }

        PagedGridResult fansList = myFansService.queryMyFansList(writerId,page,pageSize);

        return GraceJSONResult.ok(fansList);
    }

    @Override
    public GraceJSONResult queryRatio(String writerId) {
        if (StringUtils.isBlank(writerId)) {
            return GraceJSONResult.errorCustom(ResponseStatusEnum.WRITER_ID_IS_NULL_ERROR);
        }
//        Integer manCounts = myFansService.queryFansCounts(writerId, Sex.man);
//        Integer womanCounts = myFansService.queryFansCounts(writerId, Sex.woman);
//
//        FansCountsVO fansCountsVO = new FansCountsVO();
//        fansCountsVO.setManCounts(manCounts);
//        fansCountsVO.setWomanCounts(womanCounts);

        FansCountsVO fansCountsVO = myFansService.queryFansESCounts(writerId);
        return GraceJSONResult.ok(fansCountsVO);
    }

    @Override
    public GraceJSONResult queryRatioByRegion(String writerId) {
        if (StringUtils.isBlank(writerId)) {
            return GraceJSONResult.errorCustom(ResponseStatusEnum.WRITER_ID_IS_NULL_ERROR);
        }
        // List<RegionRatioVO> regionRatioVOS =  myFansService.queryRegionRatioCounts(writerId);
        List<RegionRatioVO> regionRatioVOS =  myFansService.queryRegionRatioESCounts(writerId);
        return GraceJSONResult.ok(regionRatioVOS);
    }

    @Override
    public GraceJSONResult forceUpdateFanInfo(String relationId, String fanId) {
        myFansService.forceUpdateFanInfo(relationId,fanId);
        return GraceJSONResult.ok();
    }
}
